package emf2gwtbridge;

import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
import org.eclipse.emf.codegen.ecore.genmodel.GenRuntimePlatform;
import org.eclipse.emf.codegen.ecore.genmodel.generator.GenBaseGeneratorAdapter;
import org.eclipse.emf.codegen.jet.JETEmitter;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.Monitor;

public class RequestFactoryGen extends GenBaseGeneratorAdapter {

	protected static final JETEmitterDescriptor[] JET_EMITTER_DESCRIPTORS = {
			new JETEmitterDescriptor("RequestFactory.javajet",
					"emf2gwtbridge.generators.RequestFactory"),
			new JETEmitterDescriptor("ServiceLocator.javajet",
					"emf2gwtbridge.generators.ServiceLocator") };

	@Override
	protected Diagnostic generateModel(Object object, Monitor monitor) {
		GenPackage p = (GenPackage) object;
		if (p.getGenModel().getRuntimePlatform() == GenRuntimePlatform.GWT) {
			JETEmitter requestFactory = getJETEmitter(JET_EMITTER_DESCRIPTORS,
					0);
			JETEmitter serviceLocator = getJETEmitter(JET_EMITTER_DESCRIPTORS,
					1);

			generateJava(p.getGenModel().getModelDirectory(),
					GeneratorUtils.getRequestFactoryPackage(p),
					GeneratorUtils.getRequestFactoryClassName(p),
					requestFactory, new Object[] { p }, monitor);
			generateJava(p.getGenModel().getModelDirectory(),
					GeneratorUtils.getServiceLocatorPackageName(p),
					GeneratorUtils.getServiceLocatorClassName(p),
					serviceLocator, new Object[] { p }, monitor);
		}
		return Diagnostic.OK_INSTANCE;
	}
}
